package com.example.service;

import com.example.common.Result;
import com.example.entity.Institutions;
import com.example.mapper.InstitutionsMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class InstitutionsService {

    @Resource
    private InstitutionsMapper institutionsMapper;

    public Result add(Institutions institutions) {
        if(!institutionsMapper.add(institutions)){
            return Result.error("添加失败");
        }
        return Result.success("添加成功");
    }

    public Result delete(Institutions institutions) {
        if(!institutionsMapper.delete(institutions)){
            return Result.error("删除失败");
        }
        return Result.success("删除成功");
    }

    public Result update(Institutions institutions) {
        if(!institutionsMapper.update(institutions)){
            return Result.error("更新失败");
        }
        return Result.success("更新成功");
    }

    public Result search(Institutions institutions) {
        List<Institutions> result = institutionsMapper.searchByName(institutions);
        return Result.success(result);
    }

    public Result get(Institutions institutions) {
        Institutions get = institutionsMapper.getById(institutions.getId());
        return Result.success(get);
    }

    public Result list() {
        List<Institutions> list = institutionsMapper.list();
        return Result.success(list);
    }

    public Result listAll() {
        List<Institutions> list = institutionsMapper.listAll();
        return Result.success(list);
    }
}
